#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
    协程
    2017-1-19 姚彧 创建
    
'''

import asyncio
import threading

@asyncio.coroutine
def compute(x, y):
    print("Compute %s + %s ..." % (x, y))
    yield from asyncio.sleep(1.0)
    return x + y

@asyncio.coroutine
def print_sum(x, y):
    result = yield from compute(x, y)
    print("%s + %s = %s" % (x, y, result))

@asyncio.coroutine
def doTask():
    for i in range(10):
        print(i)

tasks = [doTask(), print_sum(1, 2)]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
